<template>
    <div style="display: flex">
        <el-date-picker
            v-model="time"
            :picker-options="pickerOptions"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
        </el-date-picker>
        <el-button type="primary" @click="downloadOrderData">数据导出</el-button>
    </div>
</template>

<script>/**
 * @author zhaojiuyi
 * @date 2023/6/5
 * */
import {downloadOrderDataRequest} from "@/network/order";

export default {
    name: "OrderDataExport",
    data(){
        return {
            time: "",
            pickerOptions: {
                shortcuts: [{
                    text: '最近一周',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近一个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近三个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                        picker.$emit('pick', [start, end]);
                    }
                }]
            }
        }
    },
    methods: {
        downloadOrderData(){
            if (!this.time) return this.$errorMessage("请选择时间范围")
            const[start,end] = this.time
            downloadOrderDataRequest(1,start,end)

        }
    }
}
</script>

<style scoped>

</style>
